#ifndef BOX2D_H
#define BOX2D_H

#include "vertex2d.h"
#include <memory>

namespace RealScan
{

// Represents a spatial bounding box in a quadtree node
template <typename T>
struct Box2D
{
    // Center of the bounding box
    Vertex2D center;

    // Half-side length of the bounding box (must be > 0)
    double radius;

    // Child nodes (pointers are null if no child exists)
    std::unique_ptr<Box2D> child[4];

    // Flag indicating whether the box is a leaf node
    bool leaf;

    // Hash table containing vertices and associated data within this box
    std::unordered_map<Vertex2D, T> hashTable;

    /// Constructs a Box with the given center and radius
    /// \param center The center position of the box
    /// \param radius The half-side length of the box (must be > 0)
    Box2D(const Vertex2D& _center, double _radius) 
        : center(_center), radius(_radius), leaf(true) 
    {
        if (radius <= 0) {
            throw std::invalid_argument("Radius must be greater than zero.");
        }
    }
};

} /* RealScan */

#endif /* BOX2D_H */